package de.hwrberlin.remo.diagram.custom.util;

import java.util.List;

import org.eclipse.jface.dialogs.MessageDialog;

import de.hwrberlin.remo.algorithm.UserInterface;
import de.hwrberlin.remo.diagram.part.RemoDiagramEditor;
import de.hwrberlin.remo.model.ElementState;
import de.hwrberlin.remo.model.Fact;
import de.hwrberlin.remo.model.KnowledgeBaseElement;

public class DiagramEditorUserInterface implements UserInterface {

//	private final Color HIGHLIGHT_COLOR = new Color(null, 210, 210, 210);
//	private final Color NORMAL_COLOR    = new Color(null, 255, 255, 255);
	
	@SuppressWarnings("unused")
	private RemoDiagramEditor editor;
//	
	public DiagramEditorUserInterface(RemoDiagramEditor editor) {
		this.editor = editor;
	}

	@Override
	public void highlightElement(KnowledgeBaseElement element) {
//		setElementBackgroundColor(element, HIGHLIGHT_COLOR);
	}

	@Override
	public void unhighlightElement(KnowledgeBaseElement element) {
//		setElementBackgroundColor(element, NORMAL_COLOR);
	}
	
	@Override
	public void unhighlightAllElement(List<KnowledgeBaseElement> elements) {
		for(KnowledgeBaseElement element : elements) {
			unhighlightElement(element);
		}
	}
	
//	private void setElementBackgroundColor(KnowledgeBaseElement element, Color color) {
//		if(editor == null) {
//			return;
//		}
//				
//		IDiagramDocument diagramDocument = editor.getDiagramDocument();
//		Diagram diagram = diagramDocument.getDiagram();
//		
//		for (EObject eObj : diagram.eContents()) {
//			if(eObj instanceof Shape) {
//				Shape shape = (Shape) eObj;
//				
//				if(shape.getElement() == element) {
//					Command cmd = SetCommand.create(editor.getEditingDomain(), shape, 
//							NotationPackage.eINSTANCE.getFillStyle_FillColor(), color.hashCode());
//					editor.getEditingDomain().getCommandStack().execute(cmd);
//				}
//			}
//		}	
//	}

	@Override
	public ElementState askForState(Fact fact) {
		List<ElementState> elementStates = ElementState.VALUES;
		String[] states = new String[elementStates.size()];
		
		for (int i = 0; i < elementStates.size(); i++) {
			states[i] = elementStates.get(i).getLiteral();
		}
		
		String message = "What's the state of element '" + fact.getName() + "'?";
		String title   = "Found fact with unkown state";
		
		MessageDialog dialog = new MessageDialog(null, title, null, 
				message, MessageDialog.QUESTION, states, 0);
		dialog.setBlockOnOpen(true);
		
		int selectedState = dialog.open();
		
		if(selectedState == -1) {
			return ElementState.UNKNOWN;
		}
		
		return elementStates.get(selectedState);
	}
}
